using System;
using System.Web.UI.WebControls;
using NUnit.Framework;
using ValidationFramework.Web.ASP;

namespace ValidationFramework.Tests
{
    [TestFixture]
    public class ValidatorGeneratorTestFixture
    {
        [Test]
        public void ValidatorGeneratorTest()
        {
            var panel = new Panel();

            var myFooStringControl = new TextBox {ID = "myFooStringControl"};
            panel.Controls.Add(myFooStringControl);

            var myFooDateTimeControl = new TextBox {ID = "myFooDateTimeControl"};
            panel.Controls.Add(myFooDateTimeControl);

            var myFooDecimalControl = new TextBox {ID = "myFooDecimalControl"};
            panel.Controls.Add(myFooDecimalControl);

            var validatorGenerator = new PropertyValidatorGenerator();
            validatorGenerator.AddAssociation(myFooStringControl, "FooString");
            validatorGenerator.AddAssociation(myFooDecimalControl, "FooDecimal");
            validatorGenerator.AddAssociation(myFooDateTimeControl, "FooDateTime");
            validatorGenerator.TypeToValidate = typeof(ValidatorGeneratorTestObject).TypeHandle;
            validatorGenerator.GenerateValidators();
            Assert.AreEqual(29, panel.Controls.Count);
        }
    }

    public class ValidatorGeneratorTestObject
    {


        [RequiredStringRule]
        [LengthStringRule(5)]
        [RangeStringRule("aaaaa", "ccccc")]
        [RegexRule("bbbbb", ErrorMessage = "fooString must be bbbbb")]
        [CompareStringRule("bbbbb", CompareOperator.Equal)]
        public string FooString
        {
            get;
            set;
        }

        [RequiredDecimalRule]
        [RequiredDecimalRule(InitialValue = 2)]
        [CompareDecimalRule(123, CompareOperator.Equal)]
        public decimal FooDecimal
        {
            get;
            set;
        }

        [CompareDateTimeRule("10 Jan 1999", CompareOperator.Equal)]
        [RequiredDateTimeRule]
        public DateTime FooDateTime
        {
            get;
            set;
        }

    }
}